package sword.T58;

/**
 * @Author: 18362
 * @Create: 2022-04-10 13:51:10 星期日
 */
public class Solution2 {
    public String reverseLeftWords(String s, int n) {
        char[] chars = s.toCharArray();
        reverse(chars, 0, n-1);
        reverse(chars, n, s.length()-1);
        reverse(chars, 0, s.length()-1);
        return String.valueOf(chars);
    }

    private void reverse(char[] chars, int left, int right) {
        int i = left, j = right;
        while (i < j) {
            char temp = chars[i];
            chars[i] = chars[j];
            chars[j] = temp;
            i++;
            j--;
        }
    }
}
